package com.atstudy.headline.web.app.controller.categories;

import com.atstudy.headline.entity.Categories;
import com.atstudy.headline.entity.Contents;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.app.service.CategoriesService;
import com.atstudy.headline.web.app.service.ContentsService;
import com.atstudy.headline.web.app.vo.categories.CategoryVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/app/category")
public class AppCategoriesController {

    @Autowired
    private CategoriesService categoriesService;

    @Autowired
    private ContentsService contentsService;


    @GetMapping("/browse")
    public Result<List<Categories>> getCategoryBrowseData() {
        LambdaQueryWrapper<Categories> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Categories::getIsActive, 1);
        List<Categories> list = categoriesService.list(queryWrapper);
        return Result.ok(list);
    }

    @GetMapping("/content-counts")
    public Result<List<Map<String, Object>>> getCategoryContentCounts() {
        List<Map<String, Object>> list = categoriesService.getCategoryContentCounts();
        return Result.ok(list);
    }

}
